package com.aaa.controller.order;

import com.aaa.entity.Order;
import com.aaa.entity.ResponseDto;
import com.aaa.service.GoodsService;
import com.aaa.service.OrderService;
import com.aaa.service.impl.GoodsServiceImpl;
import com.google.gson.Gson;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

@WebServlet("/GetOrderCensusServlet")
public class GetOrderCensusServlet extends HttpServlet {
    GoodsService goodsService;

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("application/json");
        List<Map<String, Object>> mapList = goodsService.getOrderForGoodsSensus();
        ResponseDto responseDto = new ResponseDto();
        if (mapList != null){
            responseDto.setStatus(ResponseDto.SUCCESS_CODE);
            responseDto.setData(mapList);
            responseDto.setMessage("成功");
        }else {
            responseDto.setStatus(ResponseDto.FAILURE_CODE);
            responseDto.setMessage("失败");
        }
        resp.getWriter().write(new Gson().toJson(responseDto));
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }

    @Override
    public void init(ServletConfig config) throws ServletException {
        goodsService = new GoodsServiceImpl();
    }
}
